package cn.itcast.controller;

import cn.itcast.constant.MessageConstant;
import cn.itcast.interfaces.MenuService;
import cn.itcast.pojo.Menu;
import cn.itcast.pojo.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: peterChen
 * @date: 2019/8/19 22:19
 * @description: TODO
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("menu")
public class MenuController {

    @Reference
    private MenuService menuService;

    /**
     * 根据用户名获取对应权限下展示的菜单
     * @param username
     * @return
     */
    @RequestMapping("/getMenuByUserName")
    public Result getMenuByUserName(String username){
        try {
            List<Menu> menus =  menuService.getMenuByUserName(username);
            return new Result(true, MessageConstant.GET_MENU_SUCCESS,menus);
        } catch (Exception e) {
            //e.printStackTrace();
            log.error("get menu by username error.",e);
            return new Result(false,MessageConstant.GET_MENU_FAIL);
        }
    }

}
